#ifndef VIDEOSINK_H
#define VIDEOSINK_H

#include <libavutil/pixfmt.h>
#include "FrameQueue.h"

typedef enum {
	VIDEO_PIX_FORMAT_UNKOWN = -1,

	//RGB
	VIDEO_PIX_FORMAT_RGBA,

	//YUV420P
	VIDEO_PIX_FORMAT_YV12,   // YYYYYYYY VV UU  I420
	VIDEO_PIX_FORMAT_YU12,   // YYYYYYYY UU VV

	//YUV420SP
	VIDEO_PIX_FORMAT_NV12,   // YYYYYYYY UVUV
	VIDEO_PIX_FORMAT_NV21,   // YYYYYYYY VUVU

	//YUV422
	VIDEO_PIX_FORMAT_YUV422P,// YYYYYYYY VVVV UUUU
	VIDEO_PIX_FORMAT_YUYV,   // YUYV YUYV YUYV YUYV
	VIDEO_PIX_FORMAT_UYVY,   // UYVY UYVY UYVY UYVY

	//YUV444
	VIDEO_PIX_FORMAT_YUV444P // YYYYYYYY VVVVVVVV UUUUUUUU
}VideoPixForamt;

class VideoSink
{
public:
	VideoSink():m_Width(0),m_Height(0),m_HorStride(0),
				m_VerStride(0),m_AVPixFmt(AV_PIX_FMT_NONE),
				m_DisplayX(0),m_DisplayY(0),m_DisplayW(0),m_DisplayH(0),
				m_KeepRatio(false),m_DumpFile(NULL),m_DumpCount(0),m_DumpStartCnt(0),m_ShowCnt(0),
				m_DumpIsStarted(false),m_Inited(false){}
	virtual ~VideoSink(){}
	virtual int init(int width, int height, int hor_stride, int ver_stride, AVPixelFormat format) = 0;
	virtual bool isInited() = 0;
	virtual void setDisplayArea(int x, int y, int w, int h) = 0;
	virtual int showFrame(Frame *vframe) = 0;
	virtual void setProperty(const char *pro, char *val) = 0;
	virtual void dumpPicture(const char *file, int start, int count) = 0;
	virtual void keepRatio(bool keepratio) = 0;
	
protected:
	//视频宽高
	int m_Width;
	int m_Height;

	AVPixelFormat m_AVPixFmt;

	//horizontal stride, 水平方向像素的步长，一般等于宽度
	//解码后的内存数据宽高可能会由于对齐操作可能大于视频宽高，此值即是内存数据的宽高
	uint32_t m_HorStride;
	//vertical stride,垂直方向的步长，一般用高度进行64字节对齐
	uint32_t m_VerStride;

	//视频显示位置
	int m_DisplayX;
	int m_DisplayY;
	int m_DisplayW;
	int m_DisplayH;

	bool m_KeepRatio;

	//dump file
	FILE *m_DumpFile;
	int m_DumpCount;  //dump的图片数量
	int m_DumpStartCnt; //开始帧
	int m_ShowCnt; //显示的帧数
	bool m_DumpIsStarted; //是否已经开始dump
	bool m_Inited;
};

#endif